package com.mbt.deal.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mbt.deal.R;
import com.mbt.deal.bean.OrderListBean;
import com.mbt.deal.util.HoloderUtil;
import com.mbt.deal.util.MyUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建日期：2018/8/16 on 20:05
 * 描述:
 * 作者:王甜
 */
public class OrderListAdaoter extends BaseAdapter {

    Context context;

    List<OrderListBean> orderListBeans = new ArrayList<>();

    public OrderListAdaoter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        if (orderListBeans == null) {
            return 0;
        }
        return orderListBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null || view.getTag() == null) {
            view = LayoutInflater.from(context).inflate(R.layout.adapter_order_transaction, null);
        }

        TextView txt_type = HoloderUtil.getHolderView(view, R.id.txt_type);

        TextView txt_one_price = HoloderUtil.getHolderView(view, R.id.txt_one_price);

        TextView txt_total_money = HoloderUtil.getHolderView(view, R.id.txt_total_money);
        TextView txt_maibao_count = HoloderUtil.getHolderView(view, R.id.txt_maibao_count);
        TextView txt_create_time = HoloderUtil.getHolderView(view, R.id.txt_create_time);

        OrderListBean curBean = orderListBeans.get(position);
        if (curBean != null) {
            if(curBean.getType() == 2){
                txt_type.setText("出售");
            }else if (curBean.getType() == 1){
                txt_type.setText("购买");
            }
            txt_one_price.setText("单价："+curBean.getPrice()+"$");

            txt_total_money.setText(curBean.getTotal());
            txt_maibao_count.setText(curBean.getCoinName()+":"+curBean.getNumber()+"个");
            txt_create_time.setText(curBean.getStarttime());
        }

        return view;
    }

    public void notifyData(List<OrderListBean> orderListBeans) {
        this.orderListBeans = orderListBeans;
        notifyDataSetChanged();
    }

    public void addAllData(List<OrderListBean> list) {
        orderListBeans.addAll(list);
        notifyDataSetChanged();
    }
}
